package cn.lzj.service.User.impl.user;

import cn.lzj.mapper.UserMapper;
import cn.lzj.pojo.User;
import cn.lzj.service.User.UserInfoService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Resource
    private UserMapper userMapper;
    @Override
    public User selectUserById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public boolean modifyHeadImg(Integer userId, String userHeadImg) {
        int count = userMapper.modifyHeadImg(userId, userHeadImg);
        return count==1;
    }


    @Override
    public boolean modifyEmail(Integer userId, String email) {
        User user= userMapper.selectById(userId);
        if(user!=null) {
            if (user.getUserEmail() == email) {
                System.out.println("新邮箱必须与旧邮箱不同");
                return false;
            }
            user.setUserEmail(email);
            int count = userMapper.modifyUserEmail(userId, email);
            if (count == 1) {
                return true;
            }

        }
        return false;
    }

    @Override
    public boolean modifyPhoneNo(Integer userId, String newPhone) {
        User user=userMapper.selectById(userId);
        if(user!=null){
            if(user.getTelephone()==newPhone){
                System.out.println("新号码必须与旧号码不同");
                return false;
            }
            user.setTelephone(newPhone);
            int count=userMapper.modifyUserTelephone(userId,newPhone);
            if(count==1){
                return true;
            }
        }
      return false;
    }

    @Override
    public void modifyPassword(User user) {
        userMapper.modifyUserPassword(user);
    }
}
